<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        // supplierId: {
        //   label: '供应商',
        //   type: 'list',
        //   placeholder: '请选择供应商',
        //   list: []
        // },
        partName: {
          label: '配件名称',
          placeholder: '请输入配件名称'
        },
        partCategoryId: {
          label: '类型',
          type: 'list',
          placeholder: '请选择配件类型',
          list: []
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id, property, cb) {
      this.dataForm.id = id || 0
    //  this.initSupplierList()
      this.initPartCategoryList()

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule( 'partName', 'partCategoryId', 'status'),
        initApi: 'partApi/partInfoInfo',
        saveApi: 'partApi/savePartInfo',
        updateApi: 'partApi/updatePartInfo',
        objectName: 'partInfo',
        submitCallback: cb
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    }
  }
}
</script>
